package aos.system.modules.systemAnalysis;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;

import aos.framework.core.dao.SqlDao;
import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;
import aos.framework.web.router.HttpModel;
import aos.system.common.id.IdService;
import aos.system.common.utils.SystemCons;
import aos.system.common.utils.SystemUtils;
import aos.system.dao.AosGroupDao;
import aos.system.dao.AosUserGroupDao;
import aos.system.dao.po.AosGroupPO;
import aos.system.modules.cache.CacheUserDataService;

/**
 * 信息计数管理
 *
 * @author yushaoyang
 *
 */
@Service
public class CountMessageService {

    @Autowired
    private AosGroupDao aosGroupDao;
    @Autowired
    private SqlDao sqlDao;
    @Autowired
    private IdService idService;
    @Autowired
    private CacheUserDataService cacheUserDataService;
    @Autowired
    private AosUserGroupDao aosUserGroupDao;

    /**
     * 短信计数管理页面初始化
     *
     * @param httpModel
     * @return
     */
    public void init(HttpModel httpModel) {
        AosGroupPO aosGroupPO = aosGroupDao.selectOne(Dtos.newDto("parent_id", SystemCons.ROOTNODE_PARENT_ID));
        httpModel.setAttribute("rootPO", aosGroupPO);
        httpModel.setViewPath("system/countMessage.jsp");
    }

    /**
     * 获取群组导航树
     *
     * @param httpModel
     * @return
     */
    public void getTreeData(HttpModel httpModel) {
        Dto inDto = httpModel.getInDto();
        inDto.setOrder("sort_no");
        inDto.put("is_del", SystemCons.IS.NO);
        List<AosGroupPO> aosGroupPOs = aosGroupDao.list(inDto);
        List<Dto> modelDtos = Lists.newArrayList();
        for (AosGroupPO aosGroupPO : aosGroupPOs) {
            modelDtos.add(aosGroupPO.toDto());
        }
        String treeJson = SystemUtils.toTreeModalAsyncLoad(modelDtos);
        httpModel.setOutMsg(treeJson);
    }


    /**
     * 查询群组列表
     *
     * @param httpModel
     * @return
     */
    public void listOrgs(HttpModel httpModel) {
        Dto qDto = httpModel.getInDto();
        qDto.put("is_del", SystemCons.IS.NO);
        List<Dto> groupDtos = sqlDao.list("Group.listGroupsPage", qDto);
        httpModel.setOutMsg(AOSJson.toGridJson(groupDtos, qDto.getPageTotal()));
    }

}